class Admin::CompanyCasesController < Admin::ApplicationController
  before_action :set_company_case, only: [:show, :edit, :update, :destroy]

  # GET /admin/company_cases
  def index
    @company_cases = CompanyCase.where(admin_user_id: current_user.id).order(created_at: :desc).page(params[:page]).per(10)
  end

  # GET /admin/company_cases/1
  def show
  end

  # GET /admin/company_cases/new
  def new
    @company_case = CompanyCase.new
  end

  # GET /admin/company_cases/1/edit
  def edit
  end

  # POST /admin/company_cases
  def create
    @company_case = CompanyCase.new(company_case_params.merge({admin_user_id: current_admin_user_id, company_id: current_company_id}))

    if @company_case.save
      redirect_to admin_company_cases_url, notice: '保存成功'
    else
      render :new
    end
  end

  # PATCH/PUT /admin/company_cases/1
  def update
    if @company_case.update(company_case_params)
      redirect_to admin_company_cases_url, notice: '保存成功'
    else
      render :edit
    end
  end

  # DELETE /admin/company_cases/1
  def destroy
    @company_case.destroy
    redirect_to admin_company_cases_url, notice: '删除成功'
  end

  private
    # Use callbacks to share common setup or constraints between actions.
    def set_company_case
      @company_case = CompanyCase.find_by(id: params[:id], company_id: current_company_id)
    end

    # Only allow a trusted parameter "white list" through.
    def company_case_params
      params.require(:company_case).permit(:content, :admin_user_id, :deleted_at, :company_id, :order_number)
    end
end
